import request from "@/utils/request";
import { DeviceProduct } from "./data";
import { DeviceInstance } from "@/pages/device/instance/data";

import { PropertiesMeta } from "./component/data";

export async function list(params: any) {
  return request(`/AllLinks/device-product/_query`, {
    method: 'GET',
    params: params,
  });
}

export async function saveOrUpdate(params: Partial<DeviceProduct>) {
  return request(`/AllLinks/device-product`, {
    method: 'PATCH',
    data: params,
  });
}

export async function saveDeviceProduct(params: Partial<DeviceProduct>) {
  return request(`/AllLinks/device-product`, {
    method: 'POST',
    data: params,
  });
}

export async function update(params: DeviceProduct, productId?: string) {
  return request(`/AllLinks/device-product/${productId}`, {
    method: 'PUT',
    data: params,
  });
}

export async function info(id: string) {
  return request(`/AllLinks/device-product/${id}`, {
    method: 'GET',
  });
}

export async function remove(id: string) {
  return request(`/AllLinks/device-product/${id}`, {
    method: 'DELETE',
  });
}

export async function count(params: any) {
  return request(`/AllLinks/device-product/_count`, {
    method: 'GET',
    params: params,
  })
}

export async function query(params: any) {
  return request(`/AllLinks/device-product/_query`, {
    method: 'GET',
    params: params,
  });
}

export async function queryNoPagin(params?: any) {
  return request(`/AllLinks/device-product/_query/no-paging`, {
    method: 'GET',
    params: params,
  })
}
export async function queryNoPaginInstance(params?: any) {
  return request(`/AllLinks/device-instance/product/_query/no-paging`, {
    method: 'GET',
    params: params,
  })
}

export async function deleteById(id: string) {
  return request(`/AllLinks/device-product/${id}`, {
    method: 'DELETE',
  });
}

//消息协议
export async function protocolSupport() {
  return request(`/AllLinks/protocol/supports`, {
    method: 'GET',
  });
}

//链接协议
export async function protocolTransports(id: string) {
  return request(`/AllLinks/protocol/${id}/transports`, {
    method: 'GET',
  });
}

//协议配置
export async function protocolConfiguration(support: string, transport: string) {
  return request(`/AllLinks/protocol/${support}/${transport}/configuration`, {
    method: 'GET',
  });
}

//发布状态切换
export async function deploy(id: string) {
  return request(`/AllLinks/device-product/${id}/deploy`, {
    method: 'POST',
    data: {}
  });
}

//发布状态切换
export async function unDeploy(id: string) {
  return request(`/AllLinks/device-product/${id}/undeploy`, {
    method: 'POST',
    data: {}
  });
}

//获取机构
export async function queryOrganization() {
  return request(`/AllLinks/organize/user_all`, {
    method: 'GET'
  });
}

export async function units() {
  return request(`/AllLinks/protocol/units`, {
    method: 'get'
  });
}

//获取品类分类
export async function deviceCategory() {
  return request(`/AllLinks/device/category`, {
    method: 'get'
  });
}

export async function deviceCategoryTree() {
  return request(`/AllLinks/device/category/_tree`, {
    method: 'get'
  });
}

export async function storagePolicy() {
  return request(`/AllLinks/device/product/storage/policies`, {
    method: 'get',
  });
}

//默认标签列表查询
export async function getLabelData(){
  return request(`/AllLinks/device-product/default_tag/_query`, {
    method: 'GET',
  });
}
//默认标签添加/编辑
export async function saveLabels(param:PropertiesMeta){
  return request(`/AllLinks/device-product/default_tag/_save`, {
    method: 'POST',
    headers:{'Content-Type': 'application/json'},
    data: param
  });
}
//默认标签列表删除
export async function delLabels(id: string) {
  return request(`/AllLinks/device-product/default_tag/${id}/_del`, {
    method: 'POST'
  });
}